home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / Prog / B-C / C++ CDEV.sit / C++ CDEV ƒ / MControlPanel.cp / MControlPanel.cp
Encoding:
Text File  |  1991-08-24  |  3.0 KB  |  88 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    MControlPanel.cp (MPW 3.2)
  3.  *    Copyright ©1991 David Kreindler.  All rights reserved.
  4.  *    
  5.  *    KNOWN BUGS AND SHORTCOMINGS:
  6.  *        [none]
  7.  */
  8.  
  9. #ifndef __DEVICES__
  10. #include <Devices.h>
  11. #endif
  12.  
  13. #ifndef __USCANCDEV__
  14. #include "UScanCDEV.h"                                                                        // !!! this directive will vary according to the TControlPanel subclass used
  15. #endif
  16.  
  17. #ifndef __USTANDALONE__
  18. #include <UStandAlone.h>
  19. #endif
  20.  
  21. pascal long cdev_entry(short message, short item, short numItems, short,                    // the linker will see this as CDEV_ENTRY
  22.                        EventRecord *theEvent, long cdevValue, DialogPtr cpDialog) {
  23.     static TScanCDEV *cdev;                                                                    // !!! this declaration will vary according to the TControlPanel subclass used
  24.     TStandAloneWorld *a5World;
  25.     if (message == macDev)
  26.         cdev->DoMac(&cdevValue);                                                            // TCDEF::DoMac() is static, so we do not need an A5 world to reference it
  27.     else if (message == initDev)
  28.         if (a5World = new TStandAloneWorld) {                                                // construct our A5 world
  29.             a5World->Enter();                                                                // swap in our A5 world
  30.             if (cdev = new TScanCDEV(cpDialog, numItems)) {                                    // construct our cdev; !!! this instantiation will vary according to the TControlPanel subclass used
  31.                 cdevValue = (long)a5World;                                                    // store our A5 world reference in cdevValue
  32.                 cdev->DoInit(&cdevValue);
  33.                 a5World->Leave();                                                            // restore the caller’s A5 world
  34.             }
  35.             else {                                                                            // we could not allocate our cdev
  36.                 cdevValue = cdevMemErr;                                                        // signal the error
  37.                 delete a5World;                                                                // dispose of our A5 world
  38.             }
  39.         }
  40.         else                                                                                // we could not allocate our A5 world
  41.             cdevValue = cdevMemErr;                                                            // signal the error
  42.     else {
  43.         (a5World = (TStandAloneWorld *)cdevValue)->Enter();                                    // grab our A5 world reference from cdevValue and swap it in
  44.         switch (message) {
  45.             case hitDev:
  46.                 cdev->DoHit(item - numItems, theEvent, &cdevValue);
  47.                 break;
  48.             case closeDev:
  49.                 delete cdev;                                                                // dispose of our TControlPanel instance
  50.                 delete a5World;                                                                // dispose of our A5 world; (the destructor calls Leave() for us)
  51.                 return cdevUnset;                                                            // we must return here to preclude the call to a5World->Leave(), since a5World has been destructed
  52.             case nulDev:
  53.                 cdev->DoNull(theEvent, &cdevValue);
  54.                 break;
  55.             case updateDev:
  56.                 cdev->DoUpdate(&cdevValue);
  57.                 break;
  58.             case activDev:
  59.                 cdev->DoActivate(theEvent, &cdevValue);
  60.                 break;
  61.             case deactivDev:
  62.                 cdev->DoDeactivate(theEvent, &cdevValue);
  63.                 break;
  64.             case keyEvtDev:
  65.                 cdev->DoKeyEvent(theEvent, &cdevValue);
  66.                 break;
  67.             case undoDev:
  68.                 cdev->DoUndo(&cdevValue);
  69.                 break;
  70.             case cutDev:
  71.                 cdev->DoCut(&cdevValue);
  72.                 break;
  73.             case copyDev:
  74.                 cdev->DoCopy(&cdevValue);
  75.                 break;
  76.             case pasteDev:
  77.                 cdev->DoPaste(&cdevValue);
  78.                 break;
  79.             case clearDev:
  80.                 cdev->DoClear(&cdevValue);
  81.                 break;
  82.             case cursorDev:
  83.                 cdev->DoCursor(&cdevValue);
  84.         }
  85.         a5World->Leave();                                                                    // restore the caller’s A5 world
  86.     }
  87.     return cdevValue;                                                                        // report our status
  88. }